package com.sram.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.sram.dao.UserDao;
import com.sram.entity.User;

public class UserDaoImpl implements UserDao {
	private HibernateTemplate template;
	public HibernateTemplate getTemplate() {
		return template;
	}
	public void setTemplate(HibernateTemplate template) {
		this.template = template;
	}


	public void addUser(User user) {
		template.save(user);
	}

	public void deleteUser(int id) {
		User user = (User) template.get(User.class, id);
		template.delete(user);
	}

	public User getUserByUserNameAndPassword(final String userName, final String password) {
	/*	User u = (User) template.execute(new HibernateCallback() {

			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				User u = (User) session.createQuery("from User u where u.userName=:userName and u.password=:password")
				.setParameter("userName", userName).setParameter("password", password).uniqueResult();
				return u;
			}
		});
		*/
		/*List<User> users = (List<User>) template.find("from User u where u.userName=? and u.password=?", new Object[]{userName,password});
		if(users != null && users.size() >= 1){
			return users.get(0);
		}*/
		return null;
	}

	public void updateUser(User user) {
		template.update(user);
	}

}
